# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-cliargs
_rockname=lua_cliargs
pkgver=3.0_p2
_pkgver=${pkgver%_p*}-${pkgver##*_p}
pkgrel=2
pkgdesc="A command-line argument parsing module for Lua"
url="https://github.com/amireh/lua_cliargs"
arch="noarch"
license="MIT"
checkdepends="
	lua-busted
	lua-cjson
	lua-yaml
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/amireh/$_rockname/archive/v$_pkgver.tar.gz
	support-cjson.patch
	"
builddir="$srcdir/$_rockname-$_pkgver"
options="!check"  # avoid circular dependency with lua-busted

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	checkdepends="$checkdepends lua$_v"
	# for backward compatibility (Alpine <3.18)
	provides="$provides lua$_v-cliargs=$pkgver-r$pkgrel"
done

check() {
	local lver; for lver in $_luaversions jit; do
		msg "Testing on lua$lver"
		# from_ini - missing aport lua-inifile
		lua$lver /usr/bin/busted --no-coverage --exclude-tags="from_ini"
	done
}

package() {
	local rockdir="$pkgdir/usr/lib/luarocks/rocks-common/$_rockname/$_pkgver"
	local luadir="$pkgdir/usr/share/lua/common"

	mkdir -p "$luadir"
	cp -r src/* "$luadir"/

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
e7a475f1d41249b0a35f021a6ccca46078f5b689c1927a4dd4cab80b2e4d291babaab35cf7d64fad3ebf68d871fb5177f030c7a2b28d9f55fbeb4dd26021d024  lua-cliargs-3.0_p2.tar.gz
69c1d1118a9a4f270eb458c91c4cb73621e25d9ddede8b9a2892cf551b756abb328f705e69ff1e76b3e59af26dbe2852267e0c765db7d8e8e38f014797edc347  support-cjson.patch
"
